package com.nursinghome.common.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.nursinghome.bean.RoomOccupancy;
import com.nursinghome.common.mapper.RoomOccupancyMapper;
import com.nursinghome.common.service.RoomOccupancyService;
import com.nursinghome.exception.NurisingHomeException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 程硕
* @createDate 2025-04-07 01:10:33
*/
@Service
public class RoomOccupancyServiceImpl implements RoomOccupancyService{
    @Autowired
    private RoomOccupancyMapper roomOccupancyMapper;
    @Override
    public Boolean insert(RoomOccupancy reservation) throws NurisingHomeException {

        return roomOccupancyMapper.insert(reservation) > 0;
    }

    @Override
    public Boolean update(RoomOccupancy reservation) throws NurisingHomeException {
        return roomOccupancyMapper.update(reservation) > 0;
    }

    @Override
    public Boolean delete(Integer id) throws NurisingHomeException {
        RoomOccupancy roomOccupancy = roomOccupancyMapper.selectById(id);
        if (ObjectUtil.isEmpty(roomOccupancy)){
            throw new NurisingHomeException("该数据不存在");
        };
        roomOccupancy.setIsDelete(1);
        return roomOccupancyMapper.update(roomOccupancy) > 0;
    }

    @Override
    public RoomOccupancy selectById(Integer id) {
        return roomOccupancyMapper.selectById(id);
    }

    @Override
    public List<RoomOccupancy> selectAll(RoomOccupancy roomOcc) {
        return roomOccupancyMapper.selectAll(roomOcc);
    }
}
